package com.skyworthclub.competition.utils.web;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.Map;

/**
 * @author li
 * @version 1.0
 * @since 18-10-16 下午9:36
 * 响应工具类
 **/
public class ResponseUtil {
    private static final String STATUS = "status";
    private static final String MSG = "message";
    /**成功的状态码*/
    private static final int SUCCESS = 200;
    /**失败的状态码*/
    private static final int FAILURE = 400;
    /**添加成功提示消息*/
    private static final String PUT_SUCCESS_MSG = "添加成功！";
    /**添加失败提示信息*/
    private static final String PUT_FAILURE_MSG = "添加失败！";

    /**查询成功提示消息*/
    private static final String QUERY_SUCCESS_MSG = "获取成功！";
    /**查询失败提示信息*/
    private static final String QUERY_FAILURE_MSG = "获取失败！";

    /**删除成功提示信息*/
    private static final String DELETE_SUCCESS_MSG = "删除成功";
    /**删除失败提示信息*/
    private static final String DELETE_FAILURE_MSG = "删除失败";

    /**更新成功提示信息*/
    private static final String UPDATE_SUCCESS_MSG = "修改成功";
    /**更新失败提示信息*/
    private static final String UPDATE_FAILURE_MSG = "修改失败";

    public static ResponseEntity<Map<String, Object>> putSuccessResponse(Map<String, Object> map) {
        map.put(STATUS, SUCCESS);
        map.put(MSG, PUT_SUCCESS_MSG);
        return new ResponseEntity<>(map, HttpStatus.OK);
    }

    public static ResponseEntity<Map<String, Object>> putFailureResponse(Map<String, Object> map) {
        map.put(STATUS, FAILURE);
        map.put(MSG, PUT_FAILURE_MSG);
        return new ResponseEntity<>(map, HttpStatus.BAD_REQUEST);
    }

    public static ResponseEntity<Map<String, Object>> querySuccessResponse(Map<String, Object> map) {
        map.put(STATUS, SUCCESS);
        map.put(MSG, QUERY_SUCCESS_MSG);
        return new ResponseEntity<>(map, HttpStatus.OK);
    }

    public static ResponseEntity<Map<String, Object>> queryFailureResponse(Map<String, Object> map) {
        map.put(STATUS, FAILURE);
        map.put(MSG, QUERY_FAILURE_MSG);
        return new ResponseEntity<>(map, HttpStatus.BAD_REQUEST);
    }

    public static ResponseEntity<Map<String, Object>> deleteSuccessResponse(Map<String, Object> map) {
        map.put(STATUS, SUCCESS);
        map.put(MSG, DELETE_SUCCESS_MSG);
        return new ResponseEntity<>(map, HttpStatus.OK);
    }

    public static ResponseEntity<Map<String, Object>> deleteFailureResponse(Map<String, Object> map) {
        map.put(STATUS, FAILURE);
        map.put(MSG, DELETE_FAILURE_MSG);
        return new ResponseEntity<>(map, HttpStatus.BAD_REQUEST);
    }

    public static ResponseEntity<Map<String, Object>> updateSuccessResponse(Map<String, Object> map) {
        map.put(STATUS, SUCCESS);
        map.put(MSG, UPDATE_SUCCESS_MSG);
        return new ResponseEntity<>(map, HttpStatus.OK);
    }

    public static ResponseEntity<Map<String, Object>> updateFailureResponse(Map<String, Object> map) {
        map.put(STATUS, FAILURE);
        map.put(MSG, UPDATE_FAILURE_MSG);
        return new ResponseEntity<>(map, HttpStatus.INTERNAL_SERVER_ERROR);
    }

}
